//
//  QQOnekey.m
//  分享demo
//
//  Created by pc-chtypd056 on 2018/8/8.
//  Copyright © 2018年 CTL. All rights reserved.
//

#import "QQOnekey.h"
#import "AZMetaBallCanvas.h"

@interface QQOnekey()
{
    UIButton *rightBtn;
    UILabel *label;
}

/** <#注释说明#> */
@property (nonatomic, strong) AZMetaBallCanvas *ballCanvas;
/** <#注释说明#> */
@property (nonatomic, strong) UIViewController *currentVC;
@end

@implementation QQOnekey

- (instancetype)initWithFrame:(CGRect)frame withCurrentVC:(UIViewController *)vc{
    _currentVC = vc;
    if (self = [super initWithFrame:frame]) {
        [self addSetSubViews];
    }
    return self;
}

- (void)addSetSubViews{

    _ballCanvas = [[AZMetaBallCanvas alloc]initWithFrame:self.bounds];
    [self addSubview:_ballCanvas];
    
    rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    rightBtn.frame = CGRectMake(0, 0, 50, 30);
    [rightBtn setTitle:@"清空" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(dianjiashijian) forControlEvents:UIControlEventTouchUpInside];
    _currentVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    
    [self.ballCanvas attach:rightBtn];
    
    label = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWIDTH/2, ScreenHEIGH/2, 40, 40)];
    label.text = @"50";
    label.tag = 1001;
    label.backgroundColor = [UIColor redColor];
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.layer.cornerRadius = label.frame.size.height/2;
    label.layer.masksToBounds = YES;
    [self addSubview:label];
    
    [self.ballCanvas attach:label];
    
    self.ballCanvas.didExplosion = ^(UIView *view) {
        view.hidden = NO;
        
    };
}

- (void)dianjiashijian{
    CTLog(@"清空");
    UILabel *labels = [self viewWithTag:1001];
    labels.text = @"";
    [self.ballCanvas explosion];
}

@end
